﻿using System;
using Glue;
using Glue.Converters;
using Xunit;

namespace GlueTests.MapperVerificationTests
{
    public class When_using_special_converters
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class SpecialConverter: BaseSimpleConverter<string, bool>
        {
            public override bool MapTowardsRight(string from)
            {
                return (from == "A");
            }
            
            public override string MapTowardsLeft(bool from)
            {
                return from ? "A" : "";
            }
        }

        public class DomainPerson
        {
            public String StringProperty { get; set; }
        }

        public class GuiPerson
        {
            public bool BoolProperty { get; set; }
        }

        public When_using_special_converters()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.StringProperty, gui => gui.BoolProperty, new SpecialConverter());            
        }

        [Fact]
        public void Should_verify_away_from_special_case()
        {
            mapping.GetMapperVerification().AssertMapsCorrectlyTowards(new DomainPerson());
        }

        [Fact]
        public void Should_verify_towards_special_case()
        {
            mapping.GetMapperVerification().AssertMapsCorrectlyTowards(new GuiPerson());
        }

    }
}
